<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('修改知识库类型')"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content pt-md">
    <form class="form-horizontal" id="form-knowBaseType-edit" th:object="${knowBaseType}">
        <input name="id" type="hidden" th:field="*{id}"/>
        <input id="treeId" name="parentId" type="hidden" th:field="*{parentId}"/>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">上级知识库类型：</label>
            <div class="col-sm-8">
                <div class="input-group">
                    <input class="form-control" type="text" onclick="selectKnowBaseTypeTree()" id="treeName"
                           th:field="*{parentName}" readonly="true" required>
                    <span class="input-group-addon"><i class="fa fa-search"></i></span>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">知识库类型：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="knowTypeName" th:field="*{knowTypeName}" id="knowTypeName">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">显示排序：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="orderByNo" th:field="*{orderByNo}" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">备注：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" th:field="*{memo}" name="memo">
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<script type="text/javascript">
    var prefix = ctx + "gy/know_type";

    $("#form-knowBaseType-edit").validate({
        onkeyup: false,
        rules: {
            knowTypeName: {
                remote: {
                    url: prefix + "/checkKnowBaseTypeUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        "id": function () {
                            return $("#id").val();
                        },
                        "parentId": function () {
                            return $("input[name='parentId']").val();
                        },
                        "knowTypeName": function () {
                            return $.common.trim($("#knowTypeName").val());
                        }
                    },
                    dataFilter: function (data, type) {
                        return $.validate.unique(data);
                    }
                },

            },
            orderNum: {
                digits: true
            },
        },
        messages: {
            "knowTypeName": {
                remote: "知识库类型已经存在"
            }
        },
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/edit", $('#form-knowBaseType-edit').serialize());
        }
    }

    function selectKnowBaseTypeTree() {
        var knowTypeId = $("#treeId").val();
        var excludeId = $("input[name='id']").val();
        if (knowTypeId > 0) {
            var options = {
                title: '知识库类型选择',
                width: "380",
                url: prefix + "/selectKnowBaseTypeTree/" + $("#treeId").val() + "/" + excludeId,
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        } else {
            $.modal.alertError("父知识库类型不能选择");
        }
    }

    function doSubmit(index, layero) {
            var body = $.modal.getChildFrame(index);
            $("#treeId").val(body.find('#treeId').val());
            $("#treeName").val(body.find('#treeName').val());
            $.modal.close(index);
      //  }
    }
</script>
</body>
</html>
